package com.pingbu.tijian.hospital.backapi.service;

import com.pingbu.common.bean.ResultBean;
import com.pingbu.common.utils.PbSecretUtils;
import com.pingbu.tijian.hospital.backapi.bean.entity.ClassStudent;
import com.pingbu.tijian.hospital.backapi.bean.entity.Classes;
import com.pingbu.tijian.hospital.backapi.bean.entity.JoinClassMessage;
import com.pingbu.tijian.hospital.backapi.mapper.ClassStudentMapper;
import com.pingbu.tijian.hospital.backapi.mapper.JoinClassMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class JoinClassMessageService {

    @Autowired
    private JoinClassMessageMapper joinClassMessageMapper;


    @Autowired
    private ClassStudentMapper classStudentMapper;

    //获取所有未读的加入班级的信息
    public ResultBean<JoinClassMessage> getUserInfoJoinClassMessageByClassesId(Classes param) {
      List<JoinClassMessage> joinClassMessages = joinClassMessageMapper.getUserInfoJoinClassMessageByClassesIdTwo(param);
      return ResultBean.create(0,"success",joinClassMessages);
    }

    // isUserInfoApplyJoinClass // 是否通过班级审核... 1.同意  2.不同意
    public ResultBean<Integer> isUserInfoApplyJoinClass(JoinClassMessage joinClassMessage) {

        //修改 joinClassMessage表 is_join_class 字段
        joinClassMessageMapper.userInfoisApplyJoinClass(joinClassMessage);

        if (joinClassMessage.getIs_join_class() == 1){
            ClassStudent classStudent = new ClassStudent();

            classStudent.setNoid(PbSecretUtils.uuid());
            classStudent.setStudent_noid(joinClassMessage.getStudent_id());
            classStudent.setClass_noid(joinClassMessage.getClasses_id());
            classStudentMapper.insert(classStudent);
            return  ResultBean.create(0,"success","同意班级审核..");
        }else{
            return  ResultBean.create(0,"success","未通过班级审核..");
        }
    }
}
